﻿using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using SmartSpace.Core;
using System;
using SsTool.Common;
using System.Windows.Input;

namespace SsTool.Core.Parts
{
    /// <summary>
    /// Interaction logic for ShortcutsPart.xaml
    /// </summary>
    public partial class ShortcutsPart : UserControl
    {
        /// <summary>
        /// 新建时使用的navigation
        /// </summary>
        private Navigation _newNavigation;

        private SmartSpace.Core.Application _application;

        public ShortcutsPart()
        {
            InitializeComponent();
        }

        public void SetApplication(SmartSpace.Core.Application application)
        {
            _application = application;
            LoadDatas();
        }

        private void LoadDatas()
        {
            if (_application == null)
            {
                return;
            }

            ICoreService service = App.Get<ICoreService>();
            _ctlGridShortcuts.ItemsSource = service.GetShortcuts(_application.Id);
        }

        private void _ctlBtnCreate_Click(object sender, RoutedEventArgs e)
        {
        }

        private void _ctlBtnRefresh_Click(object sender, RoutedEventArgs e)
        {
            LoadDatas();
        }

        private void _ctlBtnDelete_Click(object sender, RoutedEventArgs e)
        {
            Shortcut shortcut = _ctlGridShortcuts.SelectedItem as Shortcut;
            if (shortcut != null)
            {

                ICoreService service = App.Get<ICoreService>();
                if (service.DeleteShortcut(shortcut.NavigationId))
                {
                    MessageBox.Show("删除成功!");
                    LoadDatas();
                }
                else
                {
                    MessageBox.Show("删除失败!");
                }
            }
        }
    }
}
